import {_Echerts} from "@/echarts";

let colorObj = {
    RL: [1, 0, 0, 0],
    RB_LT: [1, 1, 0, 0],
    RT_LB: [1, 0, 0, 1],
    LR: [0, 1, 1, 1],
    LT_RB: [0, 0, 1, 1],
    LB_RT: [0, 1, 1, 0],
    BT: [0, 1, 0, 0], //[1, 1, 1, 0]
    TB: [1, 0, 1, 1] // [0, 0, 0, 1]
}
let defaultoffset = {
    '2': [0, 1],
    '3': [0, .5, 1],
    '4': [0, .34, .67, 1],
    '5': [0, .25, .50, .75, 1],
}
export default function (option, direction) {
    let color = option
    let directionObj = colorObj[direction] || colorObj['TB']
    if (typeof color === 'string') {
        return color
    } else {
        let arr = []
        let offsetArr = defaultoffset[color.length]
        color.forEach((item, index) => {
            if (typeof item === 'object') {
                arr.push({
                    color: item.color,
                    offset: item.offset
                })
            } else {
                arr.push({
                    color: item,
                    offset: offsetArr[index]
                })
            }
        })
        return new _Echerts.graphic.LinearGradient(...directionObj, arr)
    }
}